<?php

/**
 * default actions.
 *
 * @package    jiazhang
 * @subpackage default
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class defaultActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeLogin(sfWebRequest $request)
    {
        if($this->getUser()->isAuthenticated(true)) {
            $this->redirect('user/index');
        } else {
            if($request->isMethod(sfRequest::POST)) {
                $username = $request->getParameter('username');
                $password = md5($request->getParameter('password'));
                $admin_user = sfConfig::get('app_admin_user');
                $admin_password = sfConfig::get('app_admin_password');

                if($username != $admin_user || $password != $admin_password) {
                    $this->getUser()->setFlash('error', '用户名或密码错误!');
                        $this->redirect('@login');
                }
                $this->getUser()->setAuthenticated(true);
                $this->getUser()->setAttribute('user_name', $username);
                $this->redirect('user/index');
            }
        }
    }
}
